﻿using System.Collections.ObjectModel;
using System.Windows.Input;

namespace MVVMPresentation.ViewModel
{
    public class ApplicationViewModel : ObservableObject
    {
        public ObservableCollection<CustomerViewModel> Customers { get; set; }

        #region [ Commands ]

        private ICommand m_AddCustomerCommand;

        public ICommand AddCustomerCommand
        {
            get
            {
                if (m_AddCustomerCommand == null)
                {
                    m_AddCustomerCommand = new RelayCommand
                    (
                       param => Customers.Add(new CustomerViewModel()),
                       param => this.Customers.Count < 10
                    );
                }

                return m_AddCustomerCommand;
            }
        }

        private ICommand m_RemoveCustomerCommand;

        public ICommand RemoveCustomerCommand
        {
            get
            {
                if (m_RemoveCustomerCommand == null)
                {
                    m_RemoveCustomerCommand = new RelayCommand
                    (
                       param => Customers.Remove((CustomerViewModel)param),
                       param => this.Customers.Count > 0
                    );
                }

                return m_RemoveCustomerCommand;
            }
        }

        #endregion [ Commands ]

        public ApplicationViewModel()

        {
            Customers = new ObservableCollection<CustomerViewModel>();

            Customers.Add
            (
               new CustomerViewModel()
               {
                   Name = "Jan",
                   Surname = "Nowak",
                   Address = "Kraków, Polska",
                   PhoneNo = "11-11-11-11"
               }
            );

            Customers.Add
            (
               new CustomerViewModel()
               {
                   Name = "Jakub",
                   Surname = "Kowal",
                   Address = "Gdańsk, Polska",
                   PhoneNo = "222-222-222"
               }
            );
        }
    }
}